export default function debounce(fn, delay) {
    let ctx;
    let args;
    let timer = null;

    function later() {
        fn.apply(ctx, args);
        timer = null;
    }

    return function() {
        ctx = this;
        args = arguments;

        if (timer) {
            clearTimeout(timer);
            timer = null;
        }

        timer = setTimeout(later, delay);
    }
}
